package starlingui.component
{
	import com.imcrl.component.PageList;
	import com.imcrl.component.itemRender.IListItemRender;
	import com.imcrl.component.pictab.PictabItem;
	import com.imcrl.core.ClassFactory;
	import com.imcrl.effect.ShakeEffect;
	import com.imcrl.event.AdvListItemEvent;
	import com.imcrl.event.DragAndDropEvent;
	import com.imcrl.event.ListItemEvent;
	
	import starling.events.Event;
	
	import starlingui.component.itemRender.IconItemRender;
	import starlingui.component.page.AdvPage;
	
	/**
	 * 
	 * @author crl
	 * 
	 */	
	public class DeskList extends PictabItem
	{
		protected var innerList:AdvPageList;
		protected var _layout:AdvLayout;
		
		private var page:AdvPage;
		public function DeskList()
		{
			var classFactory:ClassFactory=new ClassFactory(IconItemRender);
			
			innerList=new AdvPageList(classFactory);
			innerList.allowRepeat=true;
			innerList.addEventListener(Event.COMPLETE,dispatchEvent);
			innerList.addEventListener(ListItemEvent.SELECTED,selectedHandle);
			innerList.addEventListener(AdvListItemEvent.ITEM_DRAG_RECOGNIZED,itemDragRecognizedHandle);
			innerList.addEventListener(ListItemEvent.SELECTED_SHAKE,selectedShakeHandle);
			
			this.addChild(innerList);
		}
		
		public function set layout(value:AdvLayout):void{
			_layout=value;
			innerList.layout=value;
		}
		public function get layout():AdvLayout{
			return _layout;
		}
		
		public function get selectedItem():IListItemRender{
			return innerList.selectedItem;
		}
		
		public function set selectedIndex(value:int):void{
			innerList.selectedIndex=value;	
		}
		
		
		private function selectedShakeHandle(event:ListItemEvent):void{
			if(hasEventListener(event.type)){
				this.dispatchEvent(event);
			}
		}
		
		private function selectedHandle(event:ListItemEvent):void{
			if(hasEventListener(event.type)){
				this.dispatchEvent(event);
			}
		}
		
		private function itemDragRecognizedHandle(event:AdvListItemEvent):void{
			if(hasEventListener(event.type)){
				this.dispatchEvent(event);
			}
		}
		
		override public function set data(value:*):void{
			if(value !=page){
				page=value;
				page.addEventListener(Event.COMPLETE,pageChangeHandle);
			}
			
			var fillData:Array=page.getPageData(index);
			innerList.displayList(fillData);
		}
		
		override public function get data():*{
			return page;
		}
		
		private function pageChangeHandle(event:Event):void{
			
		}
	}
}